package testes;


import java.applet.*;
import java.awt.*;

public class NewApplet extends Applet {

    //variaveis reais
    double F, ar, Lr, Mr, Ra, Rb;

    // variaveis da viga - ponto inicial em y e x e comprimento, escala
    int Vx, Vy;
    double L, s;

    // variaveis apoio1 e apoio2 - altura, largura e distancia do traco
    double AL, AH, Adt;

    // variaveis forca F - ponto inicial em x, a, b, altura, altura da seta, largura da seta
    int Fx;
    Double a, b, Fh, Fhs, Fls;

    // variaveis forca Ra e Rb - Idem forca F
    int Ry;
    Double Rh, Rhs, Rls;

    // variaveis cota a e b - ponto inicial da cota em y, altura da cota
    int Cay;
    Double Cah;

    // variaveis cota L - idem cota a e b
    int CLy;
    Double CLh;

    // variaveis diag. momento fletor - ponto inicial em y(eixo), max de pixels
    // momento max. local, momento max geral
    int My,Mp;
    Double Mh,Mmax;

    //variaveis diag. forca cortante - ponto inicial em y(eixo), max de pixels
    int Qy,Qp;

    public void init(Graphics g) {
        setBackground(Color.white);
    }

    public void start() {

        // variaveis reais
        F=10.0;  //tf
        Lr=10.0;  //m
        ar=5.0;  //m
        a=ar*L/Lr;

        // variaveis da viga
        Vx=50;
        Vy=70;
        s=2.0;
        L=s*100.0;

        // variaveis apoio1 e apoio2
        AL=s*10.0;
        AH=s*10.0;
        Adt=s*2.5;

        // variaveis forca F
        Fh=s*20.0;
        Fhs=s*2.5;
        Fls=s*1.5;

        // variaveis forca Ra e Rb
        Rh=s*15.0;
        Rhs=s*2.5;
        Rls=s*1.5;

        // variaveis cota a e b
        Cah=s*5.0;

        // variaveis cota L
        CLh=s*5.0;

        // variaveis diag. momento fletor
        Mp=(int)s*35;

        //variaveis diag. forca cortante
        Qp=(int)s*30;

    }

    public void paint(Graphics g) {

        // variaveis reais
        Ra=F*(Lr-ar)/Lr; //tf
        Rb=F*(ar)/Lr; //tf
        Mr=F*(Lr-ar)*ar/Lr; //tf

        // variaveis forca F
        b=L-a;

        Fx=Vx+a.intValue();

        // variaveis forca Ra e Rb
        Ry=Vy+(int)AH+2*(int)Adt;

        // variaveis cota a e b
        Cay=Ry+Rh.intValue()+3*Cah.intValue()/2;

        // variaveis cota L
        CLy=Cay+3*CLh.intValue()/2+10;

        // variaveis diag. momento fletor
        My=CLy+CLh.intValue()/2+15;
        Mh=F*a*b/L;
        Mmax=F*L/4;

        //variaveis diag. forca cortante
        Qy=My+Mp+Qp/2+10;

        //início da parte gráfica
        g.setColor(Color.black);
        g.drawLine(Vx,Vy,Vx+(int)L,Vy);
        //desenha a barra

        g.setColor(Color.black);
        g.drawLine(Vx,Vy,Vx-(int)AL/2,Vy+(int)AH);
        g.drawLine(Vx-(int)AL/2,Vy+(int)AH,Vx+(int)AL/2,Vy+(int)AH);
        g.drawLine(Vx+(int)AL/2,Vy+(int)AH,Vx,Vy);
       //desenha apoio1

        g.setColor(Color.black);
        g.drawLine(Vx+(int)L,Vy,Vx+(int)L-(int)AL/2,Vy+(int)AH);
        g.drawLine(Vx+(int)L-(int)AL/2,Vy+(int)AH,Vx+(int)L+(int)AL/2,Vy+(int)AH);
        g.drawLine(Vx+(int)L+(int)AL/2,Vy+(int)AH,Vx+(int)L,(int)Vy);
        g.drawLine(Vx+(int)L-(int)AL/2,Vy+(int)AH+(int)Adt,Vx+(int)L+(int)AL/2,Vy+(int)AH+(int)Adt);
       //desenha apoio2

        g.setColor(Color.magenta);
        g.drawLine(Fx,Vy,Fx,Vy-Fh.intValue());
        g.drawLine(Fx,Vy,Fx-Fls.intValue(),Vy-Fhs.intValue());
        g.drawLine(Fx,Vy,Fx+Fls.intValue(),Vy-Fhs.intValue());
       // g.drawString(String.valueOf((F.intValue()*100)/100)+"tf",(Fx+5).intValue(),Vy-(Fh.intValue()+10));
       //desenha força

        g.setColor(Color.magenta);
        g.drawLine(Vx,Ry,Vx,Ry+Rh.intValue());
        g.drawLine(Vx,Ry,Vx-Rls.intValue(),Ry+Rhs.intValue());
        g.drawLine(Vx,Ry,Vx+(Rls.intValue()),Ry+Rhs.intValue());
      //  g.drawString(String.valueOf((Ra.intValue()*100)/100)+"tf",(Vx.intValue())-35,Ry.intValue()+Rh.intValue());
       //desenha Ra

        g.setColor(Color.magenta);
//        g.drawLine(Vx+(int)L,Ry,Vx+(int)L,Ry+(int)Rh);
//        g.drawLine(Vx+(int)L,Ry,Vx-(int)Rls+(int)L,Ry+(int)Rhs);
//        g.drawLine(Vx+(int)L,Ry,Vx+(int)Rls+(int)L,Ry+(int)Rhs);
//        g.drawString(String.valueOf(((double)(int)(Rb*100))/100)+"tf",Vx+(int)L+5,Ry+(int)Rh);
       //desenha Rb

        g.setColor(Color.black);
        g.drawLine(Vx,Cay,Vx+(int)L,Cay);
//        g.drawLine(Vx,Cay+(int)Cah/2,Vx,Cay-(int)Cah/2);
//        g.drawLine(Vx+(int)a,Cay+(int)Cah/2,Vx+(int)a,Cay-(int)Cah/2);
//        g.drawLine(Vx+(int)L,Cay+(int)Cah/2,Vx+(int)L,Cay-(int)Cah/2);
//        g.drawString(String.valueOf(((double)(int)((Lr-ar)*100))/100)+"m",Vx+(int)L-(int)b/2-10,Cay-3);
//        g.drawString(String.valueOf(((double)(int)(ar*100))/100+ "m"),Vx+(int)a/2-10,Cay-3);
//       //desenha cotas a e b

        g.setColor(Color.black);
        g.drawLine(Vx,CLy,Vx+(int)L,CLy);
//        g.drawLine(Vx,CLy+(int)CLh/2,Vx,CLy-(int)CLh/2);
//        g.drawLine(Vx+(int)L,CLy+(int)CLh/2,Vx+(int)L,CLy-(int)CLh/2);
//        g.drawString(String.valueOf(((double)(int)(Lr*100))/100)+"m",Vx+(int)L*1/2-15,CLy-3);
       //desenha cota L

        g.setColor(Color.red);
        g.drawLine(Vx,My,Vx+(int)L,My);
//        g.drawLine(Vx+(int)L,My,Vx+(int)a,My+(int)Mh*Mp/(int)Mmax);
//        g.drawLine(Vx+(int)a,My+(int)Mh*Mp/(int)Mmax,Vx,My);
        g.setColor(Color.black);
       // g.drawLine(Vx+(int)a,My,Vx+(int)a,My+(int)Mh*Mp/(int)Mmax);
        if (a<=L/2){
           // g.drawString(String.valueOf(((double)((int)(Mr*100))/100)+"tf.m",Vx+(i nt)a+5,My+(int)Mh*Mp*2/(5*(int)Mmax));
            }
        else {
           // g.drawString(String.valueOf(((double)(int)(Mr*100))/100)+"tf.m",Vx+(int)a-55,My+(int)Mh*Mp*2/(5*(int)Mmax));
        }         //desenha diag. de momento fletor

        g.setColor(Color.blue);
        g.drawLine(Vx,Qy,Vx+(int)L,Qy);
        g.drawLine(Vx+(int)L,Qy,Vx+(int)L,Qy+(int)Rb*Qp/(int)F);
       // g.drawLine(Vx+(int)L,Qy+(int)Rb*Qp/(int)F,Vx+(int)a,Qy+(int)Rb*Qp/(int)F);
       // g.drawLine(Vx+(int)a,Qy+(int)Rb*Qp/(int)F,Vx+(int)a,Qy-(int)Ra*Qp/(int)F);
       // g.drawLine(Vx+(int)a,Qy-(int)Ra*Qp/(int)F,Vx,Qy-(int)Ra*Qp/(int)F);
        g.drawLine(Vx,Qy-(int)Ra*Qp/(int)F,Vx,Qy);
        g.setColor(Color.black);
        g.drawString(String.valueOf(((double)(int)(Ra*100))/100)+"tf",Vx-35,Qy-(int)Ra*Qp/(int)F+10);
        g.drawString(String.valueOf(((double)(int)(-Rb*100))/100)+"tf",Vx+(int)L+5,Qy+(int)Rb*Qp/(int)F);
       //desenha diag. de forças cortantes
}

    public boolean mouseDrag(Event evt,int x,int y){
        if ((y<=Vy) && (y>=Vy-Fh) && (x>=Vx) && (x<=Vx+L))
          //  a=x-Vx.intValue();
        ar=a*Lr/L;
        repaint();
        return true;
    }
}